home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / OWLINC.PAK / LISTWIND.H < prev    next >
C/C++ Source or Header  |  1997-05-06  |  27KB  |  1,024 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows
  3. // Copyright (c) 1995, 1997 by Borland International, All Rights Reserved
  4. //
  5. //$Revision:   10.16  $
  6. //
  7. // Definition of TListWindow class
  8. //----------------------------------------------------------------------------
  9. #if !defined(OWL_LISTWIND_H)
  10. #define OWL_LISTWIND_H
  11.  
  12. #if !defined(OWL_DEFS_H)
  13. # include <owl/defs.h>
  14. #endif
  15. #if !defined(BI_PLAT_WIN32)
  16. # error OWL: listwind.h only supports WIN32 targets
  17. #endif
  18. #if !defined(OWL_COMMCTRL_H)
  19. # include <owl/commctrl.h>
  20. #endif
  21.  
  22. #if defined(BI_NAMESPACE)
  23. namespace OWL {
  24. #endif
  25.  
  26. // Generic definitions/compiler options (eg. alignment) preceeding the 
  27. // definition of classes
  28. #include <services/preclass.h>
  29.  
  30. class _OWLCLASS TListWindow;
  31. class _OWLCLASS TLwFindInfo;
  32. class _OWLCLASS TLwHitTestInfo;
  33. class _OWLCLASS TLwComparator;
  34.  
  35. // Constant representing all mask flags of LV_COLUMN/LV_ITEM
  36. //
  37. #if !defined(LVCF_ALL)
  38. # define LVCF_ALL  (LVCF_FMT|LVCF_SUBITEM|LVCF_TEXT|LVCF_WIDTH)
  39. #endif
  40. #if !defined(LVIF_ALL)
  41. # define LVIF_ALL  (LVIF_TEXT|LVIF_IMAGE|LVIF_PARAM|LVIF_STATE)
  42. #endif
  43.  
  44. //
  45. // class TLwFindInfo
  46. // ~~~~~ ~~~~~~~~~~~
  47. // A structure to find an item in a TListWindow.
  48. //
  49. class _OWLCLASS TLwFindInfo : public LV_FINDINFO {
  50.   public:
  51.     TLwFindInfo(LV_FINDINFO);   // make a copy
  52.     TLwFindInfo();
  53.  
  54.     // Accessors
  55.     //
  56.     void SetData(TParam2 param);
  57.     void SetPartial(char far* text = 0);
  58.     void SetString(char far* text = 0);
  59.     void SetSubstring(char far* text = 0);
  60.     void SetWrap(bool = true);
  61.  
  62.   protected:
  63.     void Init();
  64. };
  65.  
  66. //
  67. // class TLwHitTestInfo
  68. // ~~~~~ ~~~~~~~~~~~~~~
  69. // Determines if a point is somewhere on an item or not.
  70. //
  71. class _OWLCLASS TLwHitTestInfo : public LV_HITTESTINFO {
  72.   public:
  73.     TLwHitTestInfo();
  74.     TLwHitTestInfo(TPoint& p);
  75.     TLwHitTestInfo(LV_HITTESTINFO); // make a copy
  76.  
  77.     void    SetPoint(TPoint& p);
  78.     int     GetIndex();
  79.     uint    GetFlags();
  80.  
  81.   protected:
  82.     void    Init();
  83. };
  84.  
  85. //
  86. // class TLwComparator
  87. // ~~~~~ ~~~~~~~~~~~~~
  88. // A base class for comparisons to sort items.
  89. //
  90. class _OWLCLASS TLwComparator {
  91.   public:
  92.     // Return value is < 0 if item1 < item2
  93.     //                 = 0 if item1 == item2
  94.     //                 > 0 if item1 > item2
  95.     // lParam is user-defined value
  96.     //
  97.     virtual int Compare(uint32 item1, uint32 item2, uint32 lParam) const;
  98. };
  99.  
  100. //
  101. // class TListWindItem
  102. // ~~~~~ ~~~~~~~~~~~~~
  103. // Object representing an item of a TListWindow control - i.e. contains
  104. // information about the item's icon, label, state and application-defined
  105. // value
  106. //
  107. class _OWLCLASS TListWindItem : public LV_ITEM {
  108.   public:
  109.     // State of an item.
  110.     //
  111.     enum TListState {
  112.       Focus           = LVIS_FOCUSED,         // Only one item has focus
  113.       Selected        = LVIS_SELECTED,        // Marked as selected
  114.       Cut             = LVIS_CUT,             // Marked for cut & paste
  115.       DropHilited     = LVIS_DROPHILITED,     // Marked as drop target
  116.       OverlayMask     = LVIS_OVERLAYMASK,     // Retrieve one-based overlay image index
  117.       StateImageMask  = LVIS_STATEIMAGEMASK,  // Retrieve one-based state image index
  118.     };
  119.  
  120.     // Construct an empty ListWindItem structure; typically used for 
  121.     // retrieving information about an existing item. For example,
  122.     //
  123.     //    TListWindItem lstItem;
  124.     //    ListWindow->GetItem(lstItem, index, subItem);
  125.     //    ShowString(lstItem.GetText());
  126.     // 
  127.     TListWindItem(uint msk = LVIF_ALL, bool allocCache = true);        
  128.  
  129.     // Make a copy from 'raw' system structure
  130.     //
  131.     TListWindItem(const LV_ITEM& lvItem);
  132.  
  133.     // Construct an object which represents an item to be
  134.     // added/inserted into a Listview control. For example,
  135.     //
  136.     //  TListWindItem lstItem(database.FieldName(fldIndex), fldIndex);
  137.     //  ListWindow->AddItem(lstItem);
  138.     //
  139.     TListWindItem(const char* text, int subitem = 0, int len = 0);
  140.  
  141.     // Construct an object representing an existing item from a ListView 
  142.     // constrol.
  143.     //
  144.     TListWindItem(const TListWindow& ctl, int index, int subItem, 
  145.                   uint msk = LVIF_ALL);
  146.    ~TListWindItem();
  147.  
  148.     // Retrieve/Set item's text
  149.     //
  150.     char*     GetText() const;
  151.     void      GetText(char* buff, int len = 0) const;
  152.     void      SetText(const char* text, int len = 0);
  153.  
  154.     // Index is the 0-based "row"
  155.     //
  156.     int       GetIndex() const;
  157.     void      SetIndex(int);
  158.  
  159.     // Column number
  160.     //
  161.     int       GetSubItem() const;
  162.     void      SetSubItem(int);
  163.  
  164.     // Extra data
  165.     //
  166.     uint32    GetItemData() const;
  167.     void      SetItemData(uint32);
  168.  
  169.     // ImageList index
  170.     //
  171.     int       GetImageIndex() const;
  172.     void      SetImageIndex(int index);
  173.  
  174.     // State of the item. See TListState for details.
  175.     //
  176.     int       GetState() const;
  177.     void      SetState(TListState state);
  178.  
  179.     // ImageList index for the state
  180.     //
  181.     int       GetStateImage() const;
  182.     void      SetStateImage(int index);
  183.  
  184.     // Cache management routines
  185.     //
  186.     void      AllocCache(bool setpszText = true);
  187.     void      FlushCache();
  188.  
  189.   protected:
  190.     void            Init();
  191.     TAPointer<char> Cache;
  192. };
  193.  
  194. //
  195. // class TListWindColumn
  196. // ~~~~~ ~~~~~~~~~~~~~~~
  197. // A column in the TListWindow.
  198. //
  199. class _OWLCLASS TListWindColumn : public LV_COLUMN {
  200.   public:
  201.     // How to align a column
  202.     //
  203.     enum TFormat {
  204.       Left   = LVCFMT_LEFT,           // Left justified
  205.       Center = LVCFMT_CENTER,         // Centered
  206.       Right  = LVCFMT_RIGHT,          // Right justified
  207.     };
  208.  
  209.     // Zeroes out members and allocates a cache for the column text.
  210.     // Use this constructor to create a TListWindColumn object used for
  211.     // retrieving information about an existing column..
  212.     //
  213.     TListWindColumn(uint mask = LVCF_ALL, int subItem = 0);
  214.  
  215.     // Construct a ListWindColumn object from a control. This constructor
  216.     // provides a quick way to construct and retrieve information about a
  217.     // column
  218.     //
  219.     TListWindColumn(const TListWindow& ctl, int index, uint mask = LVCF_ALL,
  220.                     int subItem = 0);
  221.                     
  222.     // Make a copy of system structure
  223.     //
  224.     TListWindColumn(const LV_COLUMN& lvColumn);       
  225.  
  226.     // Quick ways to construct TListWindColumn object when inserting/adding
  227.     // new columns to a Listview control
  228.     //
  229.     // Use the first one if you want to just specify the index and text -
  230.     // OWL will compute the text extent from the default GUI font]
  231.     // Use the second one one if you want more control over the formatting]
  232.     //
  233.     TListWindColumn(char* txt, int width, TFormat how = Left, int subItem = 0);
  234.    ~TListWindColumn();
  235.  
  236.     // Initialize members of object
  237.     //
  238.     void              SetText(const char* txt, int = 0);
  239.     void              SetFormat(TFormat how);
  240.     void              SetWidth(int pixels, char* txt = 0);
  241.     void              SetSubItem(int subItem);               
  242.     
  243.     // Retrieve information from object
  244.     // [NOTE: These members only return static data currently in the
  245.     //        structure.]
  246.     //
  247.     char*             GetText() const     { return pszText;      }
  248.     TFormat           GetFormat() const   { return TFormat(fmt); }
  249.     int               GetWidth() const    { return cx;           }
  250.     int               GetSubItem() const  { return iSubItem;     }
  251.  
  252.     // Cache management routines
  253.     //
  254.     void              AllocCache(bool setpszText = true);
  255.     void              FlushCache();
  256.  
  257.   protected:
  258.     void              Init();
  259.     TAPointer<char>   Cache;
  260. };
  261.  
  262. //
  263. // class TListWindow
  264. // ~~~~~ ~~~~~~~~~~~
  265. // Encapsulates the ListView control, a window that displays a collection 
  266. // of items, each item consisting of an icon and a label. List view controls 
  267. // provide several ways of arranging items and displaying individual items. 
  268. // For example, additional information about each item can be displayed in 
  269. // columns to the right of the icon and label.
  270. //
  271. class _OWLCLASS TListWindow : public TControl {
  272.   public:
  273.     // How to arrange the items in the control
  274.     //
  275.     enum TArrangeCode {
  276.       Default       = LVA_DEFAULT,     // Use default for control style
  277.       Left          = LVA_ALIGNLEFT,   // Align items to the left edge
  278.       Top           = LVA_ALIGNTOP,    // Align items to the top edge
  279.       SnapToGrid    = LVA_SNAPTOGRID,  // Snap icons to nearest grid position
  280.     };
  281.  
  282.     // Type of iamge list for use with the control
  283.     //
  284.     enum TImageListType {
  285.       Normal = LVSIL_NORMAL,    // Normal image list.
  286.       Small  = LVSIL_SMALL,     // Small icons for LVS_SMALLICON
  287.       State  = LVSIL_STATE,     // State image
  288.     };
  289.  
  290.     // Type of rectangle boundaries to retrieve
  291.     //
  292.     enum TItemRectType {
  293.       Bounds        = LVIR_BOUNDS,     // Entire boundary (icon and label)
  294.       Icon          = LVIR_ICON,       // Only the icon
  295.       Label         = LVIR_LABEL,      // Only the label
  296.       SelectBounds  = LVIR_SELECTBOUNDS// Union of Icon+Label but no colmns
  297.     };
  298.  
  299.     // Next item to retrieve from current item
  300.     //
  301.     enum TNextItemCode {
  302.       // Only one relational property
  303.       //
  304.       Above       = LVNI_ABOVE,       // Directly above
  305.       All         = LVNI_ALL,         // By index
  306.       Below       = LVNI_BELOW,       // Directly below
  307.       ToLeft      = LVNI_TOLEFT,      // Left of
  308.       ToRight     = LVNI_TORIGHT,     // Right of
  309.  
  310.       // Can have multiple state searches
  311.       //
  312.       Cut         = LVNI_CUT,         // Marked for cut & paste
  313.       DropHilited = LVNI_DROPHILITED, // Marked for drop target
  314.       Focused     = LVNI_FOCUSED,     // Marked as having focus
  315.       Selected    = LVNI_SELECTED,    // Marked as selected
  316.     };
  317.  
  318.     // Constructors and destructors
  319.     //
  320.     TListWindow(TWindow* parent, int id, int x, int y, int w, int h,
  321.                 TModule* module = 0);
  322.     TListWindow(TWindow* parent, int resourceId, TModule* module = 0);
  323.    ~TListWindow();
  324.  
  325.     // Column manipulation
  326.     //
  327.     int   InsertColumn(int colNum, const TListWindColumn&);
  328.     bool  DeleteColumn(int colNum);
  329.     bool  GetColumn(int index, LV_COLUMN*); 
  330.     bool  GetColumn(int index, TListWindColumn& column) const; 
  331.     int   GetColumnWidth(int index) const;
  332.     bool  SetColumn(int index, const TListWindColumn&);
  333.     bool  SetColumnWidth(int index, int width);
  334.  
  335.     // Retrieve/Set item data
  336.     //
  337.     bool GetItem(TListWindItem&, int index = -1, int subitem = -1) const;
  338.     bool SetItem(TListWindItem&, int index = -1, int subitem = -1);
  339.  
  340.     int  GetNextItem(int index, TNextItemCode code) const;
  341.     int  GetItemCount() const;
  342.     void SetItemCount(int numItems);
  343.     bool GetItemPosition(int index, POINT far*);        
  344.     bool GetItemPosition(int index, TPoint& pt) const;  
  345.     bool SetItemPosition(int index, const TPoint& pt);  
  346.  
  347.     bool GetItemRect(int index, RECT far*, TItemRectType);  
  348.     uint GetItemState(int index, uint mask) const;
  349.     bool SetItemState(int index, uint state, uint mask);
  350.     int  GetItemText(int index, int subItem, char* text, int size) const;
  351.  
  352.     // Add/Insert/Delete
  353.     //
  354.     int  AddItem(TListWindItem& newItem);
  355.     int  InsertItem(TListWindItem& newItem, int index = -1);
  356.  
  357.     // NOTE: The following should be named 'DeleteItem' to be consistent.
  358.     //       However, it would then hide TControl's DeleteItem...
  359.     //
  360.     bool DeleteAnItem(int itemIndex);
  361.     bool DeleteAllItems();
  362.  
  363.     // Update item attributes
  364.     //
  365.     bool SetItemText(int index, const TListWindItem& item);
  366.     bool SetItemText(int index, int subItem, const char* text);
  367.  
  368.     // Find/Sort/Arrange
  369.     //
  370.     int  FindItem(int startIndex, const TLwFindInfo* findInfo); 
  371.     bool SortItems(const TLwComparator& Comparator, uint32 lParam = 0);
  372.     bool Arrange(TArrangeCode code);
  373.  
  374.     // Item selection
  375.     //
  376.     bool IsSelected(int index) const;
  377.     int  GetSelCount(void) const;
  378.     int  GetSelIndexes(int* indexes, int maxCount) const;
  379.     int  GetSelStrings(char far** strs, int maxCount, int maxChars, int subItem = 0) const;
  380.     bool SetSel(int index, bool select);
  381.     bool SetSelIndexes(int* indexes, int numSelections, bool select);
  382.     bool SetSelItemRange(bool select, int first, int last);
  383.  
  384.     // Image list manipulation
  385.     //
  386.     HIMAGELIST CreateDragImage(int itemIndex, TPoint* upLeft);
  387.     HIMAGELIST GetImageList(TImageListType);
  388.     bool       SetImageList(HIMAGELIST list, TImageListType type);
  389.  
  390.     // Color manipulation
  391.     //
  392.     COLORREF GetBkColor();
  393.     bool     SetBkColor(COLORREF c);
  394.     COLORREF GetTextBkColor();
  395.     bool     SetTextBkColor(COLORREF c);
  396.     COLORREF GetTextColor();
  397.     bool     SetTextColor(COLORREF c);
  398.  
  399.     // Callbacks
  400.     //
  401.     uint GetCallBackMask() const;
  402.     bool SetCallBackMask(uint mask);
  403.  
  404.     // Miscellaneous
  405.     //
  406.     int  GetTopIndex() const;
  407.     HWND EditLabel(int itemIndex);
  408.     HWND GetEditControl() const;
  409.     bool Update(int index);
  410.     int  HitTest(TLwHitTestInfo&);
  411.     bool Scroll(int dx, int dy);
  412.     bool GetOrigin(POINT*);               
  413.     int  GetStringWidth(char far* text);
  414.     bool GetViewRect(RECT far*);          
  415.     bool EnsureVisible(int index, bool partialOk);
  416.     bool RedrawItems(int startIndex, int endIndex);
  417.     int  GetCountPerPage() const;
  418.  
  419.   protected:
  420.     char far* GetClassName();
  421.  
  422.   private:
  423.     TListWindow(const TListWindow&);
  424.     TListWindow& operator=(const TListWindow&);
  425.  
  426. };
  427.  
  428. // Generic definitions/compiler options (eg. alignment) following the 
  429. // definition of classes
  430. #include <services/posclass.h>
  431.  
  432. #if defined(BI_NAMESPACE)
  433. } // namespace OWL
  434. #endif
  435.  
  436. //----------------------------------------------------------------------------
  437. // Inline implementations
  438. //
  439.  
  440. //
  441. // Override this to compare two items for sorting items.
  442. // If item1 < item2, return -1.
  443. // If item1 == item2, return 0.
  444. // Else return 1.
  445. //
  446. inline int
  447. TLwComparator::Compare(uint32 item1, uint32 item2, uint32 lParam) const
  448. {
  449.   return 0;
  450. }
  451.  
  452. //
  453. // Rearrange the ListWindow
  454. //
  455. inline bool
  456. TListWindow::Arrange(TArrangeCode code)
  457. {
  458.   PRECONDITION(GetHandle());
  459.   return SendMessage(LVM_ARRANGE, (int)code) != 0;
  460. }
  461.  
  462. //
  463. // Create a drag image. The returned HIMAGELIST should be deleted.
  464. //
  465. inline HIMAGELIST
  466. TListWindow::CreateDragImage(int itemIndex, TPoint* upLeft)
  467. {
  468.   PRECONDITION(GetHandle());
  469.   return (HIMAGELIST)SendMessage(LVM_CREATEDRAGIMAGE, itemIndex, TParam2(upLeft));
  470. }
  471.  
  472. //
  473. // Deletes the column number 'colNum'
  474. //
  475. inline bool
  476. TListWindow::DeleteColumn(int colNum)
  477. {
  478.   PRECONDITION(GetHandle());
  479.   return SendMessage(LVM_DELETECOLUMN, colNum) != 0;
  480. }
  481.  
  482. //
  483. // Removes all items from the ListWindow
  484. //
  485. inline bool
  486. TListWindow::DeleteAllItems()
  487. {
  488.   PRECONDITION(GetHandle());
  489.   return SendMessage(LVM_DELETEALLITEMS) != 0;
  490. }
  491.  
  492. //
  493. // Removes one item from the ListWindow
  494. //
  495. inline bool
  496. TListWindow::DeleteAnItem(int itemIndex)
  497. {
  498.   PRECONDITION(GetHandle());
  499.   return SendMessage(LVM_DELETEITEM, itemIndex) != 0;
  500. }
  501.  
  502. //
  503. // Edit the text associated with the item number 'itemIndex'.
  504. // Similar to clicking on the label of an icon on the new shell.
  505. //
  506. inline HWND
  507. TListWindow::EditLabel(int itemIndex)
  508. {
  509.   PRECONDITION(GetHandle());
  510.   return (HWND)SendMessage(LVM_EDITLABEL, itemIndex);
  511. }
  512.  
  513. //
  514. // Makes sure the item number 'index' is visible.
  515. // Will scroll the item into view if necessary.
  516. //
  517. inline bool
  518. TListWindow::EnsureVisible(int index, bool partialOk)
  519. {
  520.   PRECONDITION(GetHandle());
  521.   return SendMessage(LVM_ENSUREVISIBLE, index, TParam2(partialOk)) != 0;
  522. }
  523.  
  524. //
  525. // Locates the item indicated by 'findInfo'.
  526. // Returns the index of the item if found.
  527. // Returns -1, if not found.
  528. //
  529. inline int
  530. TListWindow::FindItem(int startIndex, const TLwFindInfo far* findInfo)
  531. {
  532.   PRECONDITION(GetHandle());
  533.   return (int)SendMessage(LVM_FINDITEM, startIndex, TParam2(findInfo));
  534. }
  535.  
  536. //
  537. // Add item to the end of the list.
  538. //
  539. inline int
  540. TListWindow::AddItem(TListWindItem& item)
  541. {
  542.   PRECONDITION(GetHandle());
  543.   return (int)InsertItem(item, GetItemCount());
  544. }
  545.  
  546. //
  547. // Inserts the item into the position indicated by item.iItem.
  548. //
  549. inline int
  550. TListWindow::InsertItem(TListWindItem& item, int index /*= -1*/)
  551. {
  552.   PRECONDITION(GetHandle());
  553.   if (index != -1)
  554.     item.iItem = index;
  555.   return (int)SendMessage(LVM_INSERTITEM, 0, TParam2(&item));
  556. }
  557.  
  558. //
  559. // Inserts the column 'colItem' into column number 'colNum'.
  560. //
  561. inline int
  562. TListWindow::InsertColumn(int colNum, const TListWindColumn& colItem)
  563. {
  564.   PRECONDITION(GetHandle());
  565.   return (int)SendMessage(LVM_INSERTCOLUMN, colNum, TParam2(&colItem));
  566. }
  567.  
  568. //
  569. // Returns the background color of the ListWindow
  570. //
  571. inline COLORREF
  572. TListWindow::GetBkColor()
  573. {
  574.   PRECONDITION(GetHandle());
  575.   return (COLORREF)SendMessage(LVM_GETBKCOLOR);
  576. }
  577.  
  578. //
  579. // Return the callback mask.
  580. //
  581. inline uint
  582. TListWindow::GetCallBackMask() const
  583. {
  584.   PRECONDITION(GetHandle());
  585.   return (uint) CONST_CAST(TListWindow*, this)->SendMessage(LVM_GETCALLBACKMASK);
  586. }
  587.  
  588. //
  589. // Returns the column information of column number 'index'.
  590. //
  591. inline bool
  592. TListWindow::GetColumn(int index, LV_COLUMN* column) 
  593. {
  594.   PRECONDITION(column);
  595.   PRECONDITION(GetHandle());
  596.   return SendMessage(LVM_GETCOLUMN, index, TParam2(column)) != 0;
  597. }
  598.  
  599. //
  600. // Returns the column information of column number 'index'.
  601. //
  602. inline bool
  603. TListWindow::GetColumn(int index, TListWindColumn& column) const
  604. {
  605.   PRECONDITION(GetHandle());
  606.   
  607.   return CONST_CAST(TListWindow*, this)->SendMessage(LVM_GETCOLUMN, 
  608.                                                      index, 
  609.                                                      TParam2(&column)) != 0;
  610. }
  611.  
  612. //
  613. // Returns the width of the column 'index'.
  614. //
  615. inline int
  616. TListWindow::GetColumnWidth(int index) const
  617. {
  618.   PRECONDITION(GetHandle());
  619.   return int(CONST_CAST(TListWindow*, this)->SendMessage(LVM_GETCOLUMNWIDTH, 
  620.                                                          index));
  621. }
  622.  
  623. //
  624. // Returns the number of fully visible items that can fit vertically
  625. // in list or report view.
  626. //
  627. inline int
  628. TListWindow::GetCountPerPage() const
  629. {
  630.   PRECONDITION(GetHandle());
  631.   return (int)CONST_CAST(TListWindow*, this)->SendMessage(LVM_GETCOUNTPERPAGE);
  632. }
  633.  
  634. //
  635. // Returns the HWND of the edit control used for editing labels.
  636. //
  637. inline HWND
  638. TListWindow::GetEditControl() const
  639. {
  640.   PRECONDITION(GetHandle());
  641.   return (HWND)CONST_CAST(TListWindow*, this)->SendMessage(LVM_GETEDITCONTROL);
  642. }
  643.  
  644. //
  645. // Returns the IMAGELIST for the type.
  646. //
  647. inline HIMAGELIST
  648. TListWindow::GetImageList(TImageListType type)
  649. {
  650.   PRECONDITION(GetHandle());
  651.   return (HIMAGELIST)SendMessage(LVM_GETIMAGELIST, type);
  652. }
  653.  
  654. //
  655. // Returns the information specified by item.
  656. //
  657. inline bool
  658. TListWindow::GetItem(TListWindItem& item, int index /*= -1*/,
  659.                      int subItem /*= -1*/) const
  660. {
  661.   PRECONDITION(GetHandle());
  662.   if (index != -1)
  663.     item.iItem = index;
  664.   if (subItem != -1)
  665.     item.iSubItem = subItem;
  666.   return CONST_CAST(TListWindow*, this)->SendMessage(LVM_GETITEM, 0, TParam2(&item)) != 0;
  667. }
  668.  
  669. //
  670. // Returns the number of items total in the ListWindow
  671. //
  672. inline int
  673. TListWindow::GetItemCount() const
  674. {
  675.   PRECONDITION(GetHandle());
  676.   return (int)CONST_CAST(TListWindow*, this)->SendMessage(LVM_GETITEMCOUNT);
  677. }
  678.  
  679. //
  680. // Returns the item's position.
  681. //
  682. inline bool
  683. TListWindow::GetItemPosition(int index, POINT far* p)  
  684. {
  685.   PRECONDITION(GetHandle());
  686.   return SendMessage(LVM_GETITEMPOSITION, index, TParam2(p)) != 0;
  687. }
  688.  
  689. //
  690. //
  691. //
  692. inline bool 
  693. TListWindow::GetItemPosition(int index, TPoint& pt) const
  694. {
  695.   PRECONDITION(GetHandle());
  696.   return CONST_CAST(TListWindow*, this)->SendMessage(LVM_GETITEMPOSITION, index, TParam2(&pt)) != 0;
  697. }
  698.  
  699. //
  700. // Returns the item's size.
  701. // TItemRectType indicates what type of rectangle to return.
  702. //
  703. inline bool
  704. TListWindow::GetItemRect(int index, RECT* r, TItemRectType type) 
  705. {
  706.   PRECONDITION(GetHandle());
  707.   r->left = type;
  708.   return SendMessage(LVM_GETITEMRECT, index, TParam2(r)) != 0;
  709. }
  710.  
  711. //
  712. // Returns the current state of the item (selected, focused, etc.)
  713. //
  714. inline uint
  715. TListWindow::GetItemState(int index, uint mask) const
  716. {
  717.   PRECONDITION(GetHandle());
  718.   return (uint)CONST_CAST(TListWindow*, this)->SendMessage(LVM_GETITEMSTATE, index, TParam2(mask));
  719. }
  720.  
  721. //
  722. // Returns the text of the item.
  723. //
  724. inline int
  725. TListWindow::GetItemText(int index, int subItem, char* text, int size) const
  726. {
  727.   PRECONDITION(GetHandle());
  728.   TListWindItem item(text, subItem, size);
  729.   return (int)CONST_CAST(TListWindow*, this)->SendMessage(LVM_GETITEMTEXT, index, TParam2(&item));
  730. }
  731.  
  732. //
  733. // Returns the index of the 'next' item after item 'index'.
  734. // See TNextItemCode for more details.
  735. //
  736. inline int
  737. TListWindow::GetNextItem(int index, TNextItemCode code) const
  738. {
  739.   PRECONDITION(GetHandle());
  740.   return (int)CONST_CAST(TListWindow*, this)->SendMessage(LVM_GETNEXTITEM, index, MkParam2(code, 0));
  741. }
  742.  
  743. //
  744. // Retrieves the current view origin of the ListWindow.
  745. // Returns false if current ListWindow is in list or report view.
  746. //
  747. inline bool
  748. TListWindow::GetOrigin(POINT far* p)
  749. {
  750.   PRECONDITION(GetHandle());
  751.   return SendMessage(LVM_GETORIGIN, 0, TParam2(p)) != 0;
  752. }
  753.  
  754. //
  755. // Returns the width of the text using the current ListWindow's font.
  756. //
  757. inline int
  758. TListWindow::GetStringWidth(char* text)
  759. {
  760.   PRECONDITION(GetHandle());
  761.   return (int)SendMessage(LVM_GETSTRINGWIDTH, 0, TParam2(text));
  762. }
  763.  
  764. //
  765. // Returns the text background color of the ListWindow.
  766. //
  767. inline COLORREF
  768. TListWindow::GetTextBkColor()
  769. {
  770.   PRECONDITION(GetHandle());
  771.   return (COLORREF)SendMessage(LVM_GETTEXTBKCOLOR);
  772. }
  773.  
  774. //
  775. // Returns the text color of the ListWindow.
  776. //
  777. inline COLORREF
  778. TListWindow::GetTextColor()
  779. {
  780.   PRECONDITION(GetHandle());
  781.   return (COLORREF)SendMessage(LVM_GETTEXTCOLOR);
  782. }
  783.  
  784. //
  785. // Returns the index of the topmost visible item.
  786. //
  787. inline int
  788. TListWindow::GetTopIndex() const
  789. {
  790.   PRECONDITION(GetHandle());
  791.   return (int)CONST_CAST(TListWindow*, this)->SendMessage(LVM_GETTOPINDEX);
  792. }
  793.  
  794. //
  795. // Returns the bouding rectangle of all items in the ListWindow.
  796. // ListWindow must be in icon or small icon view.
  797. //
  798. inline bool
  799. TListWindow::GetViewRect(RECT far* r)
  800. {
  801.   PRECONDITION(GetHandle());
  802.   return SendMessage(LVM_GETVIEWRECT, 0, TParam2(r)) != 0;
  803. }
  804.  
  805. //
  806. // Returns the index of the item indicated by 'info'
  807. //
  808. inline int
  809. TListWindow::HitTest(TLwHitTestInfo& info)
  810. {
  811.   PRECONDITION(GetHandle());
  812.   return (int)SendMessage(LVM_HITTEST, 0, TParam2(&info));
  813. }
  814.  
  815. //
  816. // Invalidates rectangle between the items between 'startIndex' and 'endIndex'
  817. //
  818. inline bool
  819. TListWindow::RedrawItems(int startIndex, int endIndex)
  820. {
  821.   PRECONDITION(GetHandle());
  822.   return SendMessage(LVM_REDRAWITEMS, 0, MkParam2(startIndex, endIndex)) != 0;
  823. }
  824.  
  825. //
  826. // Scroll the contents of the ListWindow.
  827. // The parameters 'dx' and 'dy' are in pixels.
  828. //
  829. inline bool
  830. TListWindow::Scroll(int dx, int dy)
  831. {
  832.   PRECONDITION(GetHandle());
  833.   return SendMessage(LVM_SCROLL, 0, MkParam2(dx, dy)) != 0;
  834. }
  835.  
  836. //
  837. // Sets the background color of the ListWindow.
  838. //
  839. inline bool
  840. TListWindow::SetBkColor(COLORREF c)
  841. {
  842.   PRECONDITION(GetHandle());
  843.   return SendMessage(LVM_SETBKCOLOR, 0, TParam2(c)) != 0;
  844. }
  845.  
  846. //
  847. // Sets the callback mask.
  848. //
  849. inline bool
  850. TListWindow::SetCallBackMask(uint mask)
  851. {
  852.   PRECONDITION(GetHandle());
  853.   return SendMessage(LVM_SETCALLBACKMASK, mask) != 0;
  854. }
  855.  
  856. //
  857. // Sets the attributes of the column 'index'
  858. //
  859. inline bool
  860. TListWindow::SetColumn(int index, const TListWindColumn& column)
  861. {
  862.   PRECONDITION(GetHandle());
  863.   return SendMessage(LVM_SETCOLUMN, index, TParam2(&column)) != 0;
  864. }
  865.  
  866. //
  867. // Sets the column width of 'index'.
  868. //
  869. inline bool
  870. TListWindow::SetColumnWidth(int index, int width)
  871. {
  872.   PRECONDITION(GetHandle());
  873.   return SendMessage(LVM_SETCOLUMNWIDTH, index, MkParam2(width, 0)) != 0;
  874. }
  875.  
  876. //
  877. // Sets the imagelist for the type.
  878. //
  879. inline bool
  880. TListWindow::SetImageList(HIMAGELIST list, TImageListType type)
  881. {
  882.   PRECONDITION(GetHandle());
  883.   return SendMessage(LVM_SETIMAGELIST, type, TParam2(list)) != 0;
  884. }
  885.  
  886. //
  887. // Sets the attributes of the item 'item'.
  888. //
  889. inline bool
  890. TListWindow::SetItem(TListWindItem& item, int index /*= -1*/, 
  891.                      int subItem /*= -1*/)
  892. {
  893.   PRECONDITION(GetHandle());
  894.   if (index != -1)
  895.     item.iItem = index;
  896.   if (subItem != -1)
  897.     item.iSubItem = subItem;
  898.   return SendMessage(LVM_SETITEM, 0, TParam2(&item)) != 0;
  899. }
  900.  
  901. //
  902. // Optimizes inserting a large number of items.
  903. //
  904. inline void
  905. TListWindow::SetItemCount(int numItems)
  906. {
  907.   PRECONDITION(GetHandle());
  908.   SendMessage(LVM_SETITEMCOUNT, numItems);
  909. }
  910.  
  911.  
  912. //
  913. // Sets the item to a particular point.
  914. // Only valid for icon or small icon view.
  915. //
  916. inline bool 
  917. TListWindow::SetItemPosition(int index, const TPoint& pt) 
  918. {
  919.   PRECONDITION(GetHandle());
  920.   return SendMessage(LVM_SETITEMPOSITION, index, MkParam2(pt.x, pt.y)) != 0;
  921. }
  922.  
  923. //
  924. // Sets the text for the item.
  925. //
  926. inline bool
  927. TListWindow::SetItemText(int index, const TListWindItem& item)
  928. {
  929.   PRECONDITION(GetHandle());
  930.   return SendMessage(LVM_SETITEMTEXT, index, TParam2(&item)) != 0;
  931. }
  932.  
  933. //
  934. //
  935. //
  936. inline bool
  937. TListWindow::SetItemText(int index, int subItem, const char* text)
  938. {
  939.   PRECONDITION(GetHandle());
  940.   return SetItemText(index, TListWindItem(text, subItem));
  941. }
  942.  
  943. //
  944. // Sets the background color of the ListWindow.
  945. //
  946. inline bool
  947. TListWindow::SetTextBkColor(COLORREF c)
  948. {
  949.   PRECONDITION(GetHandle());
  950.   return SendMessage(LVM_SETTEXTBKCOLOR, 0, TParam2(c)) != 0;
  951. }
  952.  
  953. //
  954. // Sets the text color of the items.
  955. //
  956. inline bool
  957. TListWindow::SetTextColor(COLORREF c)
  958. {
  959.   PRECONDITION(GetHandle());
  960.   return SendMessage(LVM_SETTEXTCOLOR, 0, TParam2(c)) != 0;
  961. }
  962.  
  963. //
  964. // Updates the ListWindow.
  965. // If the list window has LVS_AUTOARRANGE, the items are automatically
  966. // arranged to their proper locations.
  967. //
  968. inline bool
  969. TListWindow::Update(int index)
  970. {
  971.   PRECONDITION(GetHandle());
  972.   return SendMessage(LVM_UPDATE, index) != 0;
  973. }
  974.  
  975. //
  976. // Returns the text of the item.
  977. //
  978. inline char*
  979. TListWindItem::GetText() const
  980. {
  981.   return pszText;
  982. }
  983.  
  984. //
  985. // Returns the item's index.
  986. //
  987. inline int
  988. TListWindItem::GetIndex() const
  989. {
  990.   return iItem;
  991. }
  992.  
  993. //
  994. // Returns the column number for the item
  995. //
  996. inline int
  997. TListWindItem::GetSubItem() const
  998. {
  999.   return iSubItem;
  1000. }
  1001.  
  1002. //
  1003. // Returns the item's index.
  1004. //
  1005. inline int
  1006. TLwHitTestInfo::GetIndex()
  1007. {
  1008.   return iItem;
  1009. }
  1010.  
  1011. //
  1012. // Returns the flag for the item
  1013. //
  1014. inline uint
  1015. TLwHitTestInfo::GetFlags()
  1016. {
  1017.   return flags;
  1018. }
  1019.  
  1020. #endif  // OWL_LISTWIND_H
  1021.  
  1022.  
  1023.  
  1024.